<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css"
	href="../../bootstrap-3.3.7/dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css"
	href="../../bootstrap-3.3.7/dist/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="../../css/index.css" />
<link rel="stylesheet" type="text/css" href="../../css/personal.css" />
<link rel="stylesheet" type="text/css" href="../../css/background.css" />
<link rel="stylesheet" type="text/css" href="../../css/bootstrapValidator.min.css" />
<link rel="stylesheet" type="text/css" href="../../css/upload/fileinput.css" />

<!--上传图片  -->

<script type="text/javascript"
	src="../../bootstrap-3.3.7/dist/js/jquery.min.js"></script>
<script type="text/javascript"
	src="../../bootstrap-3.3.7/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../../js/upload/fileinput.js"></script>
<script type="text/javascript" src="../../js/upload/zh.js"></script>
<script type="text/javascript" src="../../js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/dynamic.js"></script>
<script type="text/javascript" src="../../js/login/jquery.form.min.js"></script>

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link  href="../../bootstrap-3.3.7/docs/assets/css/ie10-viewport-bug-workaround.css"
	rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>


</head>
<body>
		<h4 class="heading">批量上传</h4>
		<div class="myline"></div>
		<div class="row">
		<div class="col-md-10" style="margin-top:40px">
		<form  class="form-horizontal" id="multiform" action="multiupload" enctype="multipart/form-data" method="post"  style="padding-top:20px">
			<div class="form-group">
				<label class="col-md-2 control-label">库类别:</label>
				<div class="col-md-10" id="ku" class="row" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label" >excel文件：</label>
				<div class="col-md-8">
	        	 <input id="excelinput" name="excelinput" type="file">
	        	 </div>
    		</div>
    		<div class="form-group" >
    			<label class="col-md-2 control-label" >知识文件：</label>
    			<div class="col-md-8">
    				<input id="filesinput" name="filesinput" type="file" data-min-file-count="1" data-max-file-count="60" multiple webkitdirectory>
    				<p class="help-block">(请选择doc、pdf、excel、ppt、avi、mp4、rmvb、caj格式的文件,单个文件大小不超过10M,包含文件个数最大为60个)</p>
    			</div>
    		</div>
    		<div class="form-group" >
    			<div class="col-md-1"></div>
    			<div class="col-md-10">
    			   <p class="help-block" style="color:red;font-weight: bold"><span >特别注意:&nbsp;&nbsp;</span>务必保证excel里的统计文件条数和文件夹里的知识数相同,文件名和篇名保持一致,重复上传的会根据文件名、作者、日期进行匹配不会入库</p>
    			 </div>
    		</div>
    		<div class="form-group">
    				<div class="col-md-5"></div>
					<div class="col-md-7">
						<button id="submitbutton" class="btn  btn-info" onclick="submitForm()">提交文件</button>
					</div>
				</div>
		</form>
		</div>
		</div>
		
		<div class="modal fade" id="fadeback" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h5 class="modal-title" id="myModalLabel">提示信息</h5>
				</div>
				<div class="modal-body">
					<textarea id="infots" name="infots" rows="10" style="width:100%" ></textarea>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">确定</button>
				</div>
			</div>
		</div>
	  </div>
	  <div class="modal fade" id="uploadwait" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width:400px;heigth:500px">
			<div class="modal-content">
				<div class="modal-header">
					<h5 class="modal-title" id="myModalLabel">提示信息</h5>
				</div>
				<div class="modal-body">
					  <span style="margin-left:80px">正在上传文件,请稍等.....</span>
				</div>
			</div>
		</div>
	  </div>
</body>
<script>
	$(function(){
		
		
		KuBindNew("kudiv", "ku", 1, "");

		dynamicBindNew("kudiv", "ku", 1);
		
		TagBind("tag", $("#ku1").val());
		$("#excelinput").fileinput({
	        browseLabel: '选择excel',
			language: 'zh', //设置语言
	        showPreview:false,
	        allowedFileExtensions: ['xls','xlsx'],//接收的文件后缀
	        showUpload: false, //是否显示上传按钮
	        showCaption: true,//是否显示标题
	        browseClass: "btn btn-primary", //按钮样式  
	        uploadAsync: false, //默认异步上传
	        maxFileSize: 1024*1024,//单位为kb，如果为0表示不限制文件大小
	        minFileCount: 1,
	        maxFileCount: 20, //表示允许同时上传的最大文件个数
	        enctype: 'multipart/form-data',
	        validateInitialCount:true,
	        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}",
	        language:'zh',
	    });
		
		$("#filesinput").fileinput({
	        browseLabel: '选择文件夹',
			language: 'zh', //设置语言
	        showPreview:false,
	        allowedFileExtensions: ['doc','pdf','docx','ppt','pptx','avi','mp4','rmvb','caj','xls','xlsx'],//接收的文件后缀
	        showUpload: false, //是否显示上传按钮
	        showCaption: true,//是否显示标题
	        browseClass: "btn btn-primary", //按钮样式  
	        uploadAsync: false, //默认异步上传
	        maxFileSize: 1024*1024,//单位为kb，如果为0表示不限制文件大小
	        minFileCount: 1,
	        maxFileCount: 60, //表示允许同时上传的最大文件个数
	        enctype: 'multipart/form-data',
	        validateInitialCount:true,
	        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!",
	        language:'zh',
	    });
		
		$('#uploadwait').on('shown.bs.modal', function () {
				var $clone = $(this).clone().css('display','block').appendTo('body');
				var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);
				top = top > 0 ? top : 0;   
				$clone.remove();   
				$(this).find('.modal-content').css("margin-top", top); 
			});
	});
	function submitForm(){
		//$("#submitbutton").attr("disabled",true);
		var kulist = $("select[name='kulist']");
		var kudata = kulist[kulist.length-1].value;
		var excelinput=$("#excelinput").val();
		var filesinput=$("#filesinput").val();
		$("#submitbutton").attr("disabled",true);
		if(excelinput==""||excelinput==null){
			alert("请选择excel");
			$("#submitbutton").attr("disabled",false)
			return;
		}
		if(filesinput==""||filesinput==null){
			$("#submitbutton").attr("disabled",false)
			alert("请选择文件夹或者你选择的文件数量超出了限制");
			return;
		}
		var uploadmodal = $("#uploadwait");
		uploadmodal.modal({backdrop: 'static', keyboard: false}); 
		uploadmodal.modal("show");
		 $("#multiform").ajaxSubmit({
			url:"multiupload",
			data:{kudata:kudata},//传递参数
			success:function(result){
				uploadmodal.modal("hide");
				var arry = result.substring(1,result.length-1).split(",");
				if(arry[0]=='tag')
					alert("excel模板信息填写不符合要求,（特别注意序号和日期的格式 ）请咨询知识管理员");
				else if(arry[1]=='tag')
				 	alert("请检查excel里文件和文件夹文件个数是否一致  或者  excel里文件名一列是否有重复记录  或者  excel里记录的文件名和文件夹里文件名是否一致");
				else if(arry[1]==0)
				{
				    var element = "成功上传  "+arry[0]+" 个文件,失败0个,重复  "+arry[2]+" 个文件\n";
				    //没有重复的
					if(arry[2]==0)
					{
						if(arry[4]==0)
							alert(element);
						else
						{
							var modal = $("#fadeback");
							element +="一、excel中生成预览文件失败的文件名序号为(请知识管理员删除该知识后重新上传):\n";
							var viewid = arry[5].split(";");
							for(var i =0;i<viewid.length-1;i++)
							{
								 if(i==0)
								 	 	element +=viewid[i];
								 	else
								 	    element +="\t"+viewid[i];
							 }
					      modal.find('#infots').val(element);
					      modal.modal("show");
						}
					}
				    //有重复的
					else{
						var modal = $("#fadeback");
						element +="一、excel中重复的文件名序号为:\n";
					    var repeatid = arry[3].split(";");
						for(var i =0;i<repeatid.length-1;i++)
						{
							 if(i==0)
							 	 	element +=repeatid[i];
							 	else
							 	    element +="\t"+repeatid[i];
						 }
						if(arry[4] !=0){
							element +="\n 二、excel中生成预览文件失败的文件名序号为(请知识管理员删除该知识后重新上传):\n";
							var viewid = arry[4].split(";");
							for(var i =0;i<viewid.length-1;i++)
							{
								 if(i==0)
								 	 	element +=viewid[i];
								 	else
								 	    element +="\t"+viewid[i];
							 }
							
							}
						
					      modal.find('#infots').val(element);
					      modal.modal("show");
						}
					}
				else {   
						 var modal = $("#fadeback");
					 	 var element = "成功上传  "+arry[0]+" 个文件,失败"+arry[1]+"个,重复  "+arry[2]+" 个文件,\n 一.请检查文件夹里文件名为 ：\n";
						 var namearry = arry[3].split(";");
						 for(var i = 0;i<namearry.length-1;i++)
							 element +="\t"+namearry[i]+";\n";
					   	 element +="和excel里的该文件的文件名一列是否一致。";
						 if(arry[2] !=0)
						 {
							 element +="\n二、excel重复的文件序号为：\n"
							 var repeatid = arry[4].split(";");
							 for(var i =0;i<repeatid.length-1;i++)
							 {
								 if(i==0)
								 	 	element +=repeatid[i];
								 	else
								 	    element +="\t"+repeatid[i];
							 }
						 }
						 if(arry[5] !=0)
						 {
							 element +="\n三、excel中生成预览文件失败的文件名序号为(请知识管理员删除该知识后重新上传):\n"
							 var viewid = arry[6].split(";");
							 for(var i =0;i<viewid.length-1;i++)
							 {
								 if(i==0)
								 	 	element +=viewid[i];
								 	else
								 	    element +="\t"+viewid[i];
							 }		 	
						 }
						 modal.find('#infots').val(element);
				         modal.modal("show");
					 }
					
				 $("#submitbutton").attr("disabled",false);
			}
		}); 
	}
</script>
</html>